package br.ita.trucocearense.server.core.remote.padraoobserver;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import br.ita.trucocearense.common.core.interfaces.remote.padraoobserver.RemoteObserver;
import br.ita.trucocearense.common.core.interfaces.remote.padraoobserver.RemoteSubject;

public class RemoteSubjectImpl extends UnicastRemoteObject implements
		RemoteSubject {
	private ArrayList<RemoteObserver> obs = new ArrayList<RemoteObserver>();

	public RemoteSubjectImpl() throws RemoteException {
	}

	@Override
	public void notifyObservers(String reference) throws RemoteException {
		for(int i = 0; i < obs.size(); i++) {
			obs.get(i).update(reference);
		}

	}

	@Override
	public void registerObserver(RemoteObserver o) throws RemoteException {
		this.obs.add(o);
		
	}

	@Override
	public void removeObserver(RemoteObserver o) throws RemoteException {
		this.obs.remove(o);
	}

	public void removeAllObservers() throws RemoteException {
		this.obs.clear();
	}
	

}
